package newsDAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class NewsJDBCUtils {
	private NewsJDBCUtils() {
	}

	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	static final String url = "jdbc:mysql://localhost:3306/newsmanagersystem";

	public static Connection getConnection() {
		Connection con = null;
		try {
			con = DriverManager.getConnection(url, "root", "58994383");
			return con;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}

	public static void close(PreparedStatement s) {
		try {
			if (s != null)
				s.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void close(ResultSet r) {
		try {
			if (r != null)
				r.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void close(Connection c) {
		try {
			if (c != null)
				c.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void closeAll(PreparedStatement s, ResultSet r, Connection c) {
		close(r);
		close(s);
		close(c);
	}
}
